﻿// See https://aka.ms/new-console-template for more information
using Config1;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

ConfigurationBuilder builder = new ConfigurationBuilder();

//自定义配置提供者
//builder.Add(new FxConfigSource() 
//{
//    Path="web.config",
//});

//自定义配置提供者，扩展方法
//builder.AddFxConfig("web.config");
builder.AddFxConfig();//如果为null,默认是web.config文件名


IConfigurationRoot configRoot =builder.Build();

ServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddScoped<TestWebConfig>();

serviceCollection.AddOptions().Configure<WebConfig>(a=>configRoot.Bind(a));


using (ServiceProvider sp = serviceCollection.BuildServiceProvider())
{
    var c=sp.GetRequiredService<TestWebConfig>();
    c.Test();
}








